package com.tjsinfo.tjsoa.mail.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.common.SessionUser;
import com.tjsinfo.tjsoa.mail.bo.ITjsEmailFolderBo;
import com.tjsinfo.tjsoa.mail.bo.ITjsemailReceivedBo;
import com.tjsinfo.tjsoa.mail.vo.TjsEmailFolder;
import com.tjsinfo.tjsoa.mail.vo.TjsemailReceived;
import com.tjsinfo.tjsoa.system.vo.User;

public class ReadReceivedMailAction extends Action{
	private ITjsemailReceivedBo tjsemailReceivedBo;
	private ITjsEmailFolderBo tjsEmailFolderBo;
	public ITjsemailReceivedBo getTjsemailReceivedBo() {
		return tjsemailReceivedBo;
	}

	public void setTjsemailReceivedBo(ITjsemailReceivedBo tjsemailReceivedBo) {
		this.tjsemailReceivedBo = tjsemailReceivedBo;
	}

	public ITjsEmailFolderBo getTjsEmailFolderBo() {
		return tjsEmailFolderBo;
	}

	public void setTjsEmailFolderBo(ITjsEmailFolderBo tjsEmailFolderBo) {
		this.tjsEmailFolderBo = tjsEmailFolderBo;
	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		try {
		String id = request.getParameter("recid");
		//Integer userid = SessionUser.getUserId(request);
		//String username=SessionUser.getUser(request).getUsername();
		TjsemailReceived tjsemailReceived = tjsemailReceivedBo.seleceById(id);//收件
		
		List<TjsemailReceived> list = tjsemailReceivedBo.seleceByemailId(tjsemailReceived.getTjsmail().getTjsmailId());
		if(list.size() > 0 && list != null){
			request.setAttribute("List", list);
		}
		if(tjsemailReceived!=null){
		request.setAttribute("received", tjsemailReceived);
		tjsemailReceivedBo.updateTjsmailReceivedStart(tjsemailReceived.getRecId(), 2);
		List<TjsEmailFolder> list2 = tjsEmailFolderBo.selectByUserId(SessionUser.getUserId(request));//文件夹邮件列表
		request.setAttribute("foldlist", list2);
		request.setAttribute("count", tjsemailReceivedBo.count(String.valueOf(SessionUser.getUserId(request)),1));
		return mapping.findForward("ok");
		} else {
			return mapping.findForward("error");
		}
	} catch (RuntimeException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return mapping.findForward("error");
	}
	}
	
}
